source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-334.rds.xz")
summary(model)
SOM of size 25x25 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.066.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
93 148 187 56 76 62 56 54 33 9 56 21 12 8 10 16 51 21 46 49
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
56 52 121 183 53 95 143 218 252 225 40 87 82 66 36 41 64 16 11 17
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
56 83 79 53 183 69 107 94 195 151 144 184 212 66 172 102 58 103 171 106
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
78 49 52 57 92 128 172 104 74 158 99 180 160 196 278 135 195 203 165 191
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
155 120 129 113 157 138 138 63 56 54 107 135 200 153 162 93 161 178 262 275
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
213 229 191 217 221 224 161 190 116 101 141 96 87 37 75 113 154 182 182 219
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
155 226 228 193 181 141 188 201 207 149 162 55 136 95 109 104 22 102 41 78
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
118 123 103 151 159 128 89 243 222 222 199 214 206 194 146 73 67 79 42 103
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
112 115 50 53 134 115 124 179 118 185 213 180 232 177 136 202 193 159 184 222
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
170 133 102 52 84 112 138 108 102 67 72 138 137 133 163 183 179 194 206 157
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
202 210 168 156 192 83 192 113 177 144 101 120 90 61 136 130 153 196 212 180
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
197 219 187 194 174 195 234 217 216 176 179 214 168 187 175 180 156 146 131 81
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
157 163 47 159 113 178 168 217 181 230 224 181 114 201 164 135 174 163 82 223
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
200 195 154 106 81 176 218 164 183 73 105 128 147 111 235 144 201 188 158 133
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
135 100 178 164 92 65 131 122 151 158 152 208 150 184 204 155 66 163 176 215
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
159 281 176 214 145 101 29 155 148 190 185 130 115 137 154 166 65 144 297 211
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
156 197 116 230 164 56 192 215 166 155 176 154 182 151 145 151 144 130 176 155
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
170 145 124 107 154 149 150 259 216 180 174 157 132 249 173 177 123 190 165 167
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
217 163 121 137 154 101 146 182 186 224 101 219 105 174 114 131 246 126 80 232
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
158 201 181 205 198 126 147 171 109 85 62 192 238 205 189 149 152 205 158 133
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
174 176 233 136 185 197 234 218 217 88 133 177 129 143 96 138 172 178 171 143
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
167 206 181 129 132 259 144 152 240 190 220 159 196 227 227 143 71 109 68 83
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
81 95 222 108 121 133 190 132 179 89 163 158 133 114 179 132 116 171 168 117
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
91 152 118 110 120 124 203 150 142 210 215 170 195 161 173 185 240 216 147 108
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
163 133 121 248 210 137 132 140 90 144 100 159 164 175 114 184 178 198 134 169
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
174 223 180 133 100 56 125 162 188 217 163 98 91 154 124 116 72 100 90 249
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
173 199 164 264 178 201 166 145 94 182 142 136 134 119 168 179 158 197 159 150
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
161 97 134 172 242 190 149 105 227 233 180 135 109 162 135 114 209 161 142 179
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
192 228 182 183 215 112 132 251 225 128 179 151 187 171 139 93 118 218 168 172
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
147 119 79 199 180 221 170 104 123 197 264 156 97 223 120 312 238 287 247 204
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
56 146 238 145 173 292 203 326 285 281 189 173 207 155 242 283 168 108 209 119
621 622 623 624 625
207 207 172 288 131
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 25*25;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "precip")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin precip
[1,] 0.89870055 0.2873321 0.3315288 -0.005917268
[2,] -0.01723183 0.8228231 0.7840086 -0.542021548
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
fecha_cnt tmax precip tmin
0.9941955 0.9913372 0.9912748 0.9906302
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-46.0 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:130.0 1st Qu.: 33.00 1st Qu.: 5.00
Median : 4.000 Median :166.0 Median : 67.00 Median :12.00
Mean : 5.668 Mean :162.5 Mean : 65.03 Mean :15.41
3rd Qu.:10.000 3rd Qu.:198.0 3rd Qu.: 97.00 3rd Qu.:23.00
Max. :12.000 Max. :300.0 Max. : 187.00 Max. :98.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.95 1st Qu.: -5.5975
Median :0.000000 Median : 0.0000 Median :40.95 Median : -2.9553
Mean :0.000486 Mean : 0.3665 Mean :40.03 Mean : -3.1441
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.18 3rd Qu.: 0.4914
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 52.0
Median : 370.0
Mean : 485.3
3rd Qu.: 704.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-115.00 Min. : 23.00
1st Qu.: 3.000 1st Qu.:118.0 1st Qu.: 48.00 1st Qu.: 57.00
Median : 9.000 Median :147.0 Median : 75.00 Median : 67.00
Mean : 7.113 Mean :145.4 Mean : 72.18 Mean : 74.74
3rd Qu.:11.000 3rd Qu.:184.0 3rd Qu.: 108.00 3rd Qu.: 84.00
Max. :12.000 Max. :350.0 Max. : 223.00 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -7.860
Median :0 Median : 0.000 Median :42.44 Median : -3.831
Mean :0 Mean : 4.565 Mean :41.44 Mean : -3.987
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.033
Max. :0 Max. :1834.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 176.0
Mean : 474.5
3rd Qu.: 445.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. :180.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:248.0 1st Qu.:141.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :275.0 Median :163.0 Median : 4.000 Median :0
Mean : 7.882 Mean :276.2 Mean :163.6 Mean : 8.559 Mean :0
3rd Qu.: 9.000 3rd Qu.:301.0 3rd Qu.:187.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :64.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 32.0
Median : 0.00000 Median :39.99 Median : -3.5556 Median : 90.0
Mean : 0.00286 Mean :38.73 Mean : -3.8687 Mean : 290.3
3rd Qu.: 0.00000 3rd Qu.:41.63 3rd Qu.: 0.4914 3rd Qu.: 541.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-46.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:137.0 1st Qu.: 35.00 1st Qu.: 5.00
Median :3.000 Median :171.0 Median : 70.00 Median :12.00
Mean :3.294 Mean :168.7 Mean : 68.46 Mean :14.87
3rd Qu.:5.000 3rd Qu.:205.0 3rd Qu.: 102.00 3rd Qu.:22.00
Max. :9.000 Max. :300.0 Max. : 187.00 Max. :67.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.88 1st Qu.: -5.6156
Median :0.000000 Median : 0.0000 Median :40.95 Median : -3.4500
Mean :0.000474 Mean : 0.3901 Mean :39.88 Mean : -3.3430
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.18 3rd Qu.: 0.4731
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 286.0
Mean : 450.9
3rd Qu.: 687.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-115.00 Min. : 23.00
1st Qu.: 3.000 1st Qu.:118.0 1st Qu.: 48.00 1st Qu.: 57.00
Median : 9.000 Median :147.0 Median : 75.00 Median : 67.00
Mean : 7.113 Mean :145.4 Mean : 72.18 Mean : 74.74
3rd Qu.:11.000 3rd Qu.:184.0 3rd Qu.: 108.00 3rd Qu.: 84.00
Max. :12.000 Max. :350.0 Max. : 223.00 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -7.860
Median :0 Median : 0.000 Median :42.44 Median : -3.831
Mean :0 Mean : 4.565 Mean :41.44 Mean : -3.987
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -1.033
Max. :0 Max. :1834.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 176.0
Mean : 474.5
3rd Qu.: 445.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.:116.0 1st Qu.: 29.00 1st Qu.: 5.00
Median :11.00 Median :153.0 Median : 60.00 Median :13.00
Mean :11.09 Mean :148.4 Mean : 57.18 Mean :16.64
3rd Qu.:12.00 3rd Qu.:184.0 3rd Qu.: 88.00 3rd Qu.:25.00
Max. :12.00 Max. :259.0 Max. : 156.00 Max. :98.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.48 1st Qu.: -4.8458
Median :0.0000000 Median : 0.0000 Median :40.96 Median : -2.4831
Mean :0.0005132 Mean : 0.3124 Mean :40.38 Mean : -2.6896
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 0.5356
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 81
Median : 513
Mean : 564
3rd Qu.: 788
Max. :2535
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. :180.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:248.0 1st Qu.:141.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :275.0 Median :163.0 Median : 4.000 Median :0
Mean : 7.882 Mean :276.2 Mean :163.6 Mean : 8.559 Mean :0
3rd Qu.: 9.000 3rd Qu.:301.0 3rd Qu.:187.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :64.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 32.0
Median : 0.00000 Median :39.99 Median : -3.5556 Median : 90.0
Mean : 0.00286 Mean :38.73 Mean : -3.8687 Mean : 290.3
3rd Qu.: 0.00000 3rd Qu.:41.63 3rd Qu.: 0.4914 3rd Qu.: 541.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-46.0 Min. :-121.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:137.0 1st Qu.: 35.00 1st Qu.: 5.00
Median :3.000 Median :171.0 Median : 70.00 Median :12.00
Mean :3.294 Mean :168.7 Mean : 68.46 Mean :14.87
3rd Qu.:5.000 3rd Qu.:205.0 3rd Qu.: 102.00 3rd Qu.:22.00
Max. :9.000 Max. :300.0 Max. : 187.00 Max. :67.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.88 1st Qu.: -5.6156
Median :0.000000 Median : 0.0000 Median :40.95 Median : -3.4500
Mean :0.000474 Mean : 0.3901 Mean :39.88 Mean : -3.3430
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.18 3rd Qu.: 0.4731
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 286.0
Mean : 450.9
3rd Qu.: 687.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-115.00 Min. : 23.00
1st Qu.: 3.000 1st Qu.:118.0 1st Qu.: 48.00 1st Qu.: 57.00
Median : 9.000 Median :147.0 Median : 75.00 Median : 67.00
Mean : 7.129 Mean :145.4 Mean : 72.08 Mean : 72.86
3rd Qu.:11.000 3rd Qu.:184.0 3rd Qu.: 108.00 3rd Qu.: 83.00
Max. :12.000 Max. :336.0 Max. : 219.00 Max. :190.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -7.456
Median :0 Median : 0.000 Median :42.44 Median : -3.831
Mean :0 Mean : 4.505 Mean :41.45 Mean : -3.948
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -0.558
Max. :0 Max. :1834.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 158.0
Mean : 475.5
3rd Qu.: 445.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:114.5 1st Qu.: 52.75 1st Qu.:177.0 1st Qu.:0
Median : 4.000 Median :131.5 Median : 75.00 Median :198.5 Median :0
Mean : 5.926 Mean :143.3 Mean : 79.46 Mean :213.0 Mean :0
3rd Qu.:11.000 3rd Qu.:151.0 3rd Qu.: 92.00 3rd Qu.:228.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.000 1st Qu.:41.67 1st Qu.: -8.624 1st Qu.: 94.03
Median : 0.000 Median :42.24 Median : -8.411 Median : 261.00
Mean : 8.971 Mean :41.31 Mean : -6.874 Mean : 396.15
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -5.203 3rd Qu.: 370.00
Max. :607.000 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.:116.0 1st Qu.: 29.00 1st Qu.: 5.00
Median :11.00 Median :153.0 Median : 60.00 Median :13.00
Mean :11.09 Mean :148.4 Mean : 57.18 Mean :16.64
3rd Qu.:12.00 3rd Qu.:184.0 3rd Qu.: 88.00 3rd Qu.:25.00
Max. :12.00 Max. :259.0 Max. : 156.00 Max. :98.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.48 1st Qu.: -4.8458
Median :0.0000000 Median : 0.0000 Median :40.96 Median : -2.4831
Mean :0.0005132 Mean : 0.3124 Mean :40.38 Mean : -2.6896
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 0.5356
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 81
Median : 513
Mean : 564
3rd Qu.: 788
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. :180.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:248.0 1st Qu.:141.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :275.0 Median :163.0 Median : 4.000 Median :0
Mean : 7.882 Mean :276.2 Mean :163.6 Mean : 8.559 Mean :0
3rd Qu.: 9.000 3rd Qu.:301.0 3rd Qu.:187.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :64.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 32.0
Median : 0.00000 Median :39.99 Median : -3.5556 Median : 90.0
Mean : 0.00286 Mean :38.73 Mean : -3.8687 Mean : 290.3
3rd Qu.: 0.00000 3rd Qu.:41.63 3rd Qu.: 0.4914 3rd Qu.: 541.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-46.0 Min. :-121.00 Min. : 0.00
1st Qu.:1.000 1st Qu.:115.0 1st Qu.: 17.00 1st Qu.: 5.00
Median :2.000 Median :145.0 Median : 42.00 Median :13.00
Mean :2.432 Mean :139.7 Mean : 41.82 Mean :17.22
3rd Qu.:3.000 3rd Qu.:167.0 3rd Qu.: 67.00 3rd Qu.:27.00
Max. :7.000 Max. :250.0 Max. : 179.00 Max. :67.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.: -4.8500
Median :0.000000 Median : 0.0000 Median :41.11 Median : -2.7331
Mean :0.000805 Mean : 0.6446 Mean :40.43 Mean : -2.8312
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.24 3rd Qu.: 0.4914
Max. :6.000000 Max. :1494.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 71.0
Median : 445.0
Mean : 519.3
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-115.00 Min. : 23.00
1st Qu.: 3.000 1st Qu.:118.0 1st Qu.: 48.00 1st Qu.: 57.00
Median : 9.000 Median :147.0 Median : 75.00 Median : 67.00
Mean : 7.129 Mean :145.4 Mean : 72.08 Mean : 72.86
3rd Qu.:11.000 3rd Qu.:184.0 3rd Qu.: 108.00 3rd Qu.: 83.00
Max. :12.000 Max. :336.0 Max. : 219.00 Max. :190.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :27.82 Min. :-17.889
1st Qu.:0 1st Qu.: 0.000 1st Qu.:40.82 1st Qu.: -7.456
Median :0 Median : 0.000 Median :42.44 Median : -3.831
Mean :0 Mean : 4.505 Mean :41.45 Mean : -3.948
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: -0.558
Max. :0 Max. :1834.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 158.0
Mean : 475.5
3rd Qu.: 445.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:114.5 1st Qu.: 52.75 1st Qu.:177.0 1st Qu.:0
Median : 4.000 Median :131.5 Median : 75.00 Median :198.5 Median :0
Mean : 5.926 Mean :143.3 Mean : 79.46 Mean :213.0 Mean :0
3rd Qu.:11.000 3rd Qu.:151.0 3rd Qu.: 92.00 3rd Qu.:228.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.000 1st Qu.:41.67 1st Qu.: -8.624 1st Qu.: 94.03
Median : 0.000 Median :42.24 Median : -8.411 Median : 261.00
Mean : 8.971 Mean :41.31 Mean : -6.874 Mean : 396.15
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -5.203 3rd Qu.: 370.00
Max. :607.000 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.:116.0 1st Qu.: 29.00 1st Qu.: 5.00
Median :11.00 Median :153.0 Median : 60.00 Median :13.00
Mean :11.09 Mean :148.4 Mean : 57.18 Mean :16.64
3rd Qu.:12.00 3rd Qu.:184.0 3rd Qu.: 88.00 3rd Qu.:25.00
Max. :12.00 Max. :259.0 Max. : 156.00 Max. :98.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.48 1st Qu.: -4.8458
Median :0.0000000 Median : 0.0000 Median :40.96 Median : -2.4831
Mean :0.0005132 Mean : 0.3124 Mean :40.38 Mean : -2.6896
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 0.5356
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 81
Median : 513
Mean : 564
3rd Qu.: 788
Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. :180.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:248.0 1st Qu.:141.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :275.0 Median :163.0 Median : 4.000 Median :0
Mean : 7.882 Mean :276.2 Mean :163.6 Mean : 8.559 Mean :0
3rd Qu.: 9.000 3rd Qu.:301.0 3rd Qu.:187.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :64.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 32.0
Median : 0.00000 Median :39.99 Median : -3.5556 Median : 90.0
Mean : 0.00286 Mean :38.73 Mean : -3.8687 Mean : 290.3
3rd Qu.: 0.00000 3rd Qu.:41.63 3rd Qu.: 0.4914 3rd Qu.: 541.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 87.0 Min. : 25.0 Min. : 0.00 Min. :0
1st Qu.:4.000 1st Qu.:191.0 1st Qu.: 85.0 1st Qu.: 4.00 1st Qu.:0
Median :5.000 Median :210.0 Median :106.0 Median :11.00 Median :0
Mean :4.529 Mean :210.2 Mean :106.6 Mean :11.51 Mean :0
3rd Qu.:5.000 3rd Qu.:230.0 3rd Qu.:127.0 3rd Qu.:18.00 3rd Qu.:0
Max. :9.000 Max. :300.0 Max. :187.0 Max. :44.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.00
1st Qu.: 0.00000 1st Qu.:37.42 1st Qu.: -5.8792 1st Qu.: 32.00
Median : 0.00000 Median :40.48 Median : -3.7642 Median : 93.05
Mean : 0.02538 Mean :39.08 Mean : -4.0764 Mean : 352.92
3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.: 0.3664 3rd Qu.: 609.00
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2535.00
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-46.0 Min. :-121.00 Min. : 0.000
1st Qu.:1.000 1st Qu.:113.0 1st Qu.: 11.00 1st Qu.: 3.000
Median :2.000 Median :142.0 Median : 36.00 Median : 8.000
Mean :2.104 Mean :136.6 Mean : 33.33 Mean : 9.272
3rd Qu.:3.000 3rd Qu.:164.0 3rd Qu.: 56.00 3rd Qu.:14.000
Max. :7.000 Max. :250.0 Max. : 134.00 Max. :35.000
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.: -4.6800
Median :0.000000 Median : 0.0000 Median :40.95 Median : -2.3308
Mean :0.001159 Mean : 0.4289 Mean :40.28 Mean : -2.4952
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.77 3rd Qu.: 0.4942
Max. :6.000000 Max. :626.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 81.0
Median : 513.0
Mean : 519.2
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-53.0 Min. :-115.00 Min. : 23.00 Min. :0
1st Qu.:1.000 1st Qu.: 84.0 1st Qu.: 13.00 1st Qu.: 57.00 1st Qu.:0
Median :2.000 Median :125.0 Median : 52.00 Median : 67.00 Median :0
Mean :2.703 Mean :111.8 Mean : 40.03 Mean : 70.94 Mean :0
3rd Qu.:4.000 3rd Qu.:149.0 3rd Qu.: 74.00 3rd Qu.: 81.00 3rd Qu.:0
Max. :8.000 Max. :250.0 Max. : 172.00 Max. :155.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.98 1st Qu.: -7.8631 1st Qu.: 64.0
Median : 0.000 Median :42.53 Median : -3.8189 Median : 261.0
Mean : 9.989 Mean :41.81 Mean : -3.6945 Mean : 743.8
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: 0.7317 3rd Qu.:1894.0
Max. :1834.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:114.5 1st Qu.: 52.75 1st Qu.:177.0 1st Qu.:0
Median : 4.000 Median :131.5 Median : 75.00 Median :198.5 Median :0
Mean : 5.926 Mean :143.3 Mean : 79.46 Mean :213.0 Mean :0
3rd Qu.:11.000 3rd Qu.:151.0 3rd Qu.: 92.00 3rd Qu.:228.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.000 1st Qu.:41.67 1st Qu.: -8.624 1st Qu.: 94.03
Median : 0.000 Median :42.24 Median : -8.411 Median : 261.00
Mean : 8.971 Mean :41.31 Mean : -6.874 Mean : 396.15
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -5.203 3rd Qu.: 370.00
Max. :607.000 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 5.00 Min. : -8.0 Min. :-58.00 Min. : 43.00 Min. :0
1st Qu.:10.00 1st Qu.:139.0 1st Qu.: 71.00 1st Qu.: 57.00 1st Qu.:0
Median :11.00 Median :170.0 Median : 96.00 Median : 66.00 Median :0
Mean :10.61 Mean :171.8 Mean : 97.27 Mean : 74.36 Mean :0
3rd Qu.:11.00 3rd Qu.:201.0 3rd Qu.:124.00 3rd Qu.: 85.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.00 Max. :190.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.38 1st Qu.: -7.456 1st Qu.: 32.0
Median : 0.0000 Median :42.38 Median : -3.831 Median : 98.0
Mean : 0.1946 Mean :41.16 Mean : -4.147 Mean : 264.7
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 351.0
Max. :81.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. :-24.0 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.:116.0 1st Qu.: 29.00 1st Qu.: 5.00
Median :11.00 Median :153.0 Median : 60.00 Median :13.00
Mean :11.09 Mean :148.4 Mean : 57.18 Mean :16.64
3rd Qu.:12.00 3rd Qu.:184.0 3rd Qu.: 88.00 3rd Qu.:25.00
Max. :12.00 Max. :259.0 Max. : 156.00 Max. :98.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:39.48 1st Qu.: -4.8458
Median :0.0000000 Median : 0.0000 Median :40.96 Median : -2.4831
Mean :0.0005132 Mean : 0.3124 Mean :40.38 Mean : -2.6896
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 0.5356
Max. :3.0000000 Max. :382.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1
1st Qu.: 81
Median : 513
Mean : 564
3rd Qu.: 788
Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 14.0 Min. :-58.00 Min. :14.00 Min. :0
1st Qu.:2.000 1st Qu.:119.0 1st Qu.: 33.00 1st Qu.:28.00 1st Qu.:0
Median :3.000 Median :151.0 Median : 63.00 Median :34.00 Median :0
Mean :3.176 Mean :146.7 Mean : 61.08 Mean :35.27 Mean :0
3rd Qu.:4.000 3rd Qu.:176.0 3rd Qu.: 88.00 3rd Qu.:42.00 3rd Qu.:0
Max. :7.000 Max. :250.0 Max. :179.00 Max. :67.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.38 1st Qu.: -5.8728 1st Qu.: 58.0
Median : 0.000 Median :41.96 Median : -3.7642 Median : 370.0
Mean : 1.135 Mean :40.77 Mean : -3.5942 Mean : 519.3
3rd Qu.: 0.000 3rd Qu.:42.87 3rd Qu.: 0.3056 3rd Qu.: 775.0
Max. :1494.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. :180.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:248.0 1st Qu.:141.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.000 Median :275.0 Median :163.0 Median : 4.000 Median :0
Mean : 7.882 Mean :276.2 Mean :163.6 Mean : 8.559 Mean :0
3rd Qu.: 9.000 3rd Qu.:301.0 3rd Qu.:187.0 3rd Qu.:13.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :64.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.26 1st Qu.: -5.8728 1st Qu.: 32.0
Median : 0.00000 Median :39.99 Median : -3.5556 Median : 90.0
Mean : 0.00286 Mean :38.73 Mean : -3.8687 Mean : 290.3
3rd Qu.: 0.00000 3rd Qu.:41.63 3rd Qu.: 0.4914 3rd Qu.: 541.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 87.0 Min. : 25.0 Min. : 0.00 Min. :0
1st Qu.:4.000 1st Qu.:191.0 1st Qu.: 85.0 1st Qu.: 4.00 1st Qu.:0
Median :5.000 Median :210.0 Median :106.0 Median :11.00 Median :0
Mean :4.529 Mean :210.2 Mean :106.6 Mean :11.51 Mean :0
3rd Qu.:5.000 3rd Qu.:230.0 3rd Qu.:127.0 3rd Qu.:18.00 3rd Qu.:0
Max. :9.000 Max. :300.0 Max. :187.0 Max. :44.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.00
1st Qu.: 0.00000 1st Qu.:37.42 1st Qu.: -5.8792 1st Qu.: 32.00
Median : 0.00000 Median :40.48 Median : -3.7642 Median : 93.05
Mean : 0.02538 Mean :39.08 Mean : -4.0764 Mean : 352.92
3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.: 0.3664 3rd Qu.: 609.00
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2535.00
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. :1.000 Min. :-46.0 Min. :-121.00 Min. : 0.000
1st Qu.:1.000 1st Qu.:113.0 1st Qu.: 11.00 1st Qu.: 3.000
Median :2.000 Median :142.0 Median : 36.00 Median : 8.000
Mean :2.104 Mean :136.6 Mean : 33.33 Mean : 9.272
3rd Qu.:3.000 3rd Qu.:164.0 3rd Qu.: 56.00 3rd Qu.:14.000
Max. :7.000 Max. :250.0 Max. : 134.00 Max. :35.000
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :28.31 Min. :-16.4992
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.: -4.6800
Median :0.000000 Median : 0.0000 Median :40.95 Median : -2.3308
Mean :0.001159 Mean : 0.4289 Mean :40.28 Mean : -2.4952
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.77 3rd Qu.: 0.4942
Max. :6.000000 Max. :626.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 81.0
Median : 513.0
Mean : 519.2
3rd Qu.: 779.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-53.0 Min. :-115.00 Min. : 23.00 Min. :0
1st Qu.:1.000 1st Qu.: 84.0 1st Qu.: 13.00 1st Qu.: 57.00 1st Qu.:0
Median :2.000 Median :125.0 Median : 52.00 Median : 67.00 Median :0
Mean :2.703 Mean :111.8 Mean : 40.03 Mean : 70.94 Mean :0
3rd Qu.:4.000 3rd Qu.:149.0 3rd Qu.: 74.00 3rd Qu.: 81.00 3rd Qu.:0
Max. :8.000 Max. :250.0 Max. : 172.00 Max. :155.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:41.98 1st Qu.: -7.8631 1st Qu.: 64.0
Median : 0.000 Median :42.53 Median : -3.8189 Median : 261.0
Mean : 9.989 Mean :41.81 Mean : -3.6945 Mean : 743.8
3rd Qu.: 0.000 3rd Qu.:43.31 3rd Qu.: 0.7317 3rd Qu.:1894.0
Max. :1834.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11.0 Min. :-27.00 Min. :158.0 Min. :0
1st Qu.: 2.000 1st Qu.:114.5 1st Qu.: 52.75 1st Qu.:177.0 1st Qu.:0
Median : 4.000 Median :131.5 Median : 75.00 Median :198.5 Median :0
Mean : 5.926 Mean :143.3 Mean : 79.46 Mean :213.0 Mean :0
3rd Qu.:11.000 3rd Qu.:151.0 3rd Qu.: 92.00 3rd Qu.:228.5 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.: 0.000 1st Qu.:41.67 1st Qu.: -8.624 1st Qu.: 94.03
Median : 0.000 Median :42.24 Median : -8.411 Median : 261.00
Mean : 8.971 Mean :41.31 Mean : -6.874 Mean : 396.15
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -5.203 3rd Qu.: 370.00
Max. :607.000 Max. :43.36 Max. : 2.825 Max. :2371.00
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 5.00 Min. : -8.0 Min. :-58.00 Min. : 43.00 Min. :0
1st Qu.:10.00 1st Qu.:139.0 1st Qu.: 71.00 1st Qu.: 57.00 1st Qu.:0
Median :11.00 Median :170.0 Median : 96.00 Median : 66.00 Median :0
Mean :10.61 Mean :171.8 Mean : 97.27 Mean : 74.36 Mean :0
3rd Qu.:11.00 3rd Qu.:201.0 3rd Qu.:124.00 3rd Qu.: 85.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.00 Max. :190.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.38 1st Qu.: -7.456 1st Qu.: 32.0
Median : 0.0000 Median :42.38 Median : -3.831 Median : 98.0
Mean : 0.1946 Mean :41.16 Mean : -4.147 Mean : 264.7
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -1.787 3rd Qu.: 351.0
Max. :81.0000 Max. :43.57 Max. : 4.216 Max. :2535.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 8.00 Min. :-24.00 Min. :-110.00 Min. : 0.00
1st Qu.:11.00 1st Qu.: 79.00 1st Qu.: -5.00 1st Qu.:11.00
Median :12.00 Median :100.00 Median : 15.00 Median :20.00
Mean :11.52 Mean : 96.13 Mean : 14.12 Mean :21.74
3rd Qu.:12.00 3rd Qu.:117.00 3rd Qu.: 36.00 3rd Qu.:30.00
Max. :12.00 Max. :166.00 Max. : 82.00 Max. :98.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.000 Min. :28.31 Min. :-16.499
1st Qu.:0.000000 1st Qu.: 0.000 1st Qu.:40.66 1st Qu.: -4.535
Median :0.000000 Median : 0.000 Median :41.65 Median : -2.733
Mean :0.001699 Mean : 1.052 Mean :41.13 Mean : -2.685
3rd Qu.:0.000000 3rd Qu.: 0.000 3rd Qu.:42.43 3rd Qu.: 0.595
Max. :3.000000 Max. :382.000 Max. :43.57 Max. : 4.216
altitud
Min. : 1
1st Qu.: 540
Median : 779
Mean : 945
3rd Qu.:1056
Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 14.0 Min. :-58.00 Min. :14.00 Min. :0
1st Qu.:2.000 1st Qu.:119.0 1st Qu.: 33.00 1st Qu.:28.00 1st Qu.:0
Median :3.000 Median :151.0 Median : 63.00 Median :34.00 Median :0
Mean :3.176 Mean :146.7 Mean : 61.08 Mean :35.27 Mean :0
3rd Qu.:4.000 3rd Qu.:176.0 3rd Qu.: 88.00 3rd Qu.:42.00 3rd Qu.:0
Max. :7.000 Max. :250.0 Max. :179.00 Max. :67.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:40.38 1st Qu.: -5.8728 1st Qu.: 58.0
Median : 0.000 Median :41.96 Median : -3.7642 Median : 370.0
Mean : 1.135 Mean :40.77 Mean : -3.5942 Mean : 519.3
3rd Qu.: 0.000 3rd Qu.:42.87 3rd Qu.: 0.3056 3rd Qu.: 775.0
Max. :1494.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. : 57.0 Min. :-35.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:146.0 1st Qu.: 52.00 1st Qu.: 4.00
Median :11.00 Median :170.0 Median : 75.00 Median :11.00
Mean :10.94 Mean :167.6 Mean : 72.98 Mean :14.77
3rd Qu.:12.00 3rd Qu.:192.0 3rd Qu.: 96.00 3rd Qu.:22.00
Max. :12.00 Max. :259.0 Max. :156.00 Max. :57.00
nevada prof_nieve longitud latitud
Min. :0.0e+00 Min. : 0.00000 Min. :27.92 Min. :-17.7550
1st Qu.:0.0e+00 1st Qu.: 0.00000 1st Qu.:38.88 1st Qu.: -5.2892
Median :0.0e+00 Median : 0.00000 Median :40.87 Median : -2.4544
Mean :7.8e-05 Mean : 0.04093 Mean :40.11 Mean : -2.6910
3rd Qu.:0.0e+00 3rd Qu.: 0.00000 3rd Qu.:41.98 3rd Qu.: 0.4942
Max. :1.0e+00 Max. :59.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 252.0
Mean : 424.1
3rd Qu.: 667.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. :180.0 Min. : 54.0 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:235.0 1st Qu.:130.0 1st Qu.: 2.00 1st Qu.:0
Median : 8.000 Median :256.0 Median :149.0 Median : 9.00 Median :0
Mean : 8.028 Mean :256.2 Mean :147.9 Mean :12.37 Mean :0
3rd Qu.: 9.000 3rd Qu.:276.0 3rd Qu.:166.0 3rd Qu.:19.00 3rd Qu.:0
Max. :12.000 Max. :352.0 Max. :244.0 Max. :64.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.79 1st Qu.: -5.8792 1st Qu.: 33.0
Median : 0.00000 Median :40.82 Median : -3.6325 Median : 108.0
Mean : 0.00473 Mean :39.14 Mean : -4.0041 Mean : 323.6
3rd Qu.: 0.00000 3rd Qu.:42.05 3rd Qu.: 0.4731 3rd Qu.: 609.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2371.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 87.0 Min. : 25.0 Min. : 0.00 Min. :0
1st Qu.:4.000 1st Qu.:191.0 1st Qu.: 85.0 1st Qu.: 4.00 1st Qu.:0
Median :5.000 Median :210.0 Median :106.0 Median :11.00 Median :0
Mean :4.529 Mean :210.2 Mean :106.6 Mean :11.51 Mean :0
3rd Qu.:5.000 3rd Qu.:230.0 3rd Qu.:127.0 3rd Qu.:18.00 3rd Qu.:0
Max. :9.000 Max. :300.0 Max. :187.0 Max. :44.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.00
1st Qu.: 0.00000 1st Qu.:37.42 1st Qu.: -5.8792 1st Qu.: 32.00
Median : 0.00000 Median :40.48 Median : -3.7642 Median : 93.05
Mean : 0.02538 Mean :39.08 Mean : -4.0764 Mean : 352.92
3rd Qu.: 0.00000 3rd Qu.:42.01 3rd Qu.: 0.3664 3rd Qu.: 609.00
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :2535.00
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 5.00 Min. :217.0 Min. :112.0 Min. : 0.000 Min. :0
1st Qu.: 7.00 1st Qu.:288.0 1st Qu.:170.0 1st Qu.: 0.000 1st Qu.:0
Median : 8.00 Median :306.0 Median :189.0 Median : 1.000 Median :0
Mean : 7.66 Mean :306.6 Mean :187.5 Mean : 2.753 Mean :0
3rd Qu.: 8.00 3rd Qu.:325.0 3rd Qu.:206.0 3rd Qu.: 4.000 3rd Qu.:0
Max. :11.00 Max. :403.0 Max. :254.0 Max. :28.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:0 1st Qu.:37.18 1st Qu.: -5.6492 1st Qu.: 27.0
Median :0 Median :38.95 Median : -3.4503 Median : 81.0
Mean :0 Mean :38.10 Mean : -3.6625 Mean : 239.6
3rd Qu.:0 3rd Qu.:40.82 3rd Qu.: 0.4914 3rd Qu.: 515.0
Max. :0 Max. :43.56 Max. : 4.2156 Max. :1167.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)